#define _CRT_SECURE_NO_WARNINGS   1

#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
using namespace std;
int ans = 1e9;
vector<int> nums;
int  n;
int f(int i)
{
	for (int j = 2; j*j <= i; ++j)
	{
		if (i%j == 0) return 0;
	}
	return 1;
}
void dfs(int x, set<int> st, int temp)
{
	if (x == n) ans = min(ans, temp);
	for (int i = 2; i <= nums[x]; ++i){
		if (nums[x] % i == 0 && f(i) && !st.count(i))
		{
			st.insert(i);
			dfs(x + 1, st, temp + i);
			st.erase(i);
		}
	}
}
int main()
{
	set<int> st;
	cin >> n;
	int ai;
	for (int i = 0; i<n; ++i)
	{
		cin >> ai;
		nums.push_back(ai);
	}
	dfs(0, st, 0);
	if (ans == 1e9)
		cout << -1;
	else
		cout << ans;
	return 0;
}